package com.hjr.calculator.algorithm;

import com.hjr.calculator.CalcStrategy;

import java.math.BigDecimal;

import static com.hjr.calculator.CalcConstant.KEEP_SCALE;
import static com.hjr.calculator.CalcConstant.ROUNDING_MODE;

public class DivideAlgorithm implements CalcStrategy {

    @Override
    public BigDecimal calc(BigDecimal num1, BigDecimal num2) {
        if (BigDecimal.ZERO.compareTo(num2) == 0)
            throw new UnsupportedOperationException("除数不能为零");
        return num1.divide(num2, KEEP_SCALE, ROUNDING_MODE);
    }
}